<template>
  <div id="evaluation-list">
    <div class="search">
      <div class="searchbox">
        <div class="searchname">课程搜索</div>
        <Input class="search-input"
               search
               enter-button
               placeholder=""
               v-model="courseName"
               @on-search="search" />
        <Select v-model="courseType"
                clearable
                class="search-select">
          <Option v-for="item in cityList"
                  :value="item.value"
                  :key="item.value">{{ item.label }}</Option>
        </Select>
      </div>
      <div class="condition">
        <span class="name">综合排序:</span>
        <ul class="order">
          <li :class="{'active':currentIndex===0}"
              @click="selectItem(0)">按时间降序</li>
          <li :class="{'active':currentIndex===1}"
              @click="selectItem(1)">按时间升序</li>
          <li :class="{'active':currentIndex===3}"
              @click="selectItem(3)">按评分升序</li>
          <li :class="{'active':currentIndex===2}"
              @click="selectItem(2)">按评分降序</li>
        </ul>
      </div>
    </div>
    <div class="desc">
      <ul class="wrap">
        <li class="item"
            v-for="item in courseInfoList"
            @click="goDetail(item)">
          <Card>
            <div class="leftpart">
              <div class="line1">
                <icon type="md-videocam"></icon>
                <span>{{item.courseName}}</span>
              </div>
              <div class="line2">
                <span>讲师：{{item.teacherName}}</span>
                <span>类型：{{item.courseType==0?'普通教学':'案例联席'}}</span>
                <span>上课时间：{{item.courseStartTime}}</span>
              </div>
            </div>
            <div class="rightpart">
              <div class="rightpart-text">
                <span>专家评论：{{item.expertComment}}条</span>&nbsp;&nbsp;&nbsp;&nbsp;
                <span>学员评论：{{item.studentComment}}条</span>&nbsp;&nbsp;&nbsp;&nbsp;
                
              </div>
              <div class="rightpart-rating">
                <span>好评度：</span>
                <Rate allow-half
                      disabled
                      v-model="item.score" />
              </div>
            </div>
          </Card>
        </li>
      </ul>
    </div>
    <div class="page">
      <Page :total="total"
            @on-change="currentChangeHandle"
            :page-size="pageSize" />
    </div>
  </div>
</template>
<script>
import InforCard from '_c/info-card'
import CountTo from '_c/count-to'
import { ChartPie, ChartBar } from '_c/charts'
import { mapState } from 'vuex'
import { getCourseInfoList } from '@/api/data'
export default {
  components: {
    InforCard,
    CountTo,
    ChartPie,
    ChartBar
  },
  computed: {
    ...mapState({
      roleId: state => state.user.roleId
    })
  },
  data () {
    return {
      cityList: [
        {
          value: '',
          label: '全部'
        },
        {
          value: '1',
          label: '案例联席'
        },
        {
          value: '0',
          label: '普通教学'
        },
      ],
      model1: '',
      currentIndex: -1,
      courseInfoList: [],
      courseName: '',
      courseType: '',
      orderName: '',
      orderNameList: [
        'timedesc', 'timeasc', 'scoredesc', 'scoreasc'
      ],
      pageSize: 5,
      pageNum: 1,
      total: 0
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    search () {
      this.getList()
    },
    // 筛选
    selectItem (index) {
      this.currentIndex = index
      this.orderName = this.orderNameList[index]
      this.getList()
    },
    goDetail (item) {
      if (this.roleId == '1') {
        this.$router.push({
          name: 'management-course-details',
          params: { item: item }
        })
      } else {
        this.$router.push({
          name: 'course-details',
          params: { item: item, t: new Date() }
        })
      }
    },
    getList () {
      let data = {
        "courseName": this.courseName,
        "courseType": this.courseType,
        "orderName": this.orderName,
        "pageSize": this.pageSize,
        "pageNum": this.pageNum
      }
      getCourseInfoList(data).then(res => {
        if (res.data.rows && res.data.rows.length > 0) {
          this.courseInfoList = res.data.rows
          this.total = res.data.total
          this.courseInfoList.map((item) => {
            item.score = item.score / 2
          })
        }
      })
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageNum = val
      this.getList()
    },
  }
}
</script>
<style lang="scss">
#evaluation-list {
  .search {
    display: flex;
    justify-content: space-between;
    height: 40px;
    line-height: 40px;
    margin-bottom: 20px;
    .searchname {
      width: 80px;
      height: 32px;
      font-size: 15px;
    }
    .searchbox {
      display: flex;
      height: 40px;
      font-size: 0;
      .search-input {
        width: 180px;
        position: relative;
        top: 4px;
        margin-right: 5px;
      }
      .search-select {
        width: 150px;
        position: relative;
        top: 4px;
      }
    }
    .condition {
      display: flex;
      font-size: 16px;
      height: 40px;
      .name {
        padding: 0 10px;
        font-size: 14px;
      }
      .order {
        display: flex;
        li {
          padding: 0 10px;
          font-size: 14px;
          box-sizing: border-box;
          cursor: pointer;
          &:hover {
            color: #57a3f3;
            border-bottom: 2px solid #57a3f3;
          }
          &.active {
            color: #57a3f3;
            border-bottom: 2px solid #57a3f3;
          }
        }
      }
    }
  }
  .desc {
    .wrap {
      .item {
        margin-bottom: 20px;
        .ivu-card {
          cursor: pointer;
          box-shadow: 0 4px 8px 0 rgba(7, 17, 27, 0.1);
          .ivu-card-body {
            display: flex;
            .leftpart {
              width: 50%;
              .line2 {
                display: flex;
                justify-content: space-between;
                font-size: 12px;
                span {
                  &:first-child {
                    display: inline-block;
                    width: 80px;
                  }
                }
              }
              .line1 {
                display: flex;
                font-size: 12px;
                i {
                  margin-right: 10px;
                  font-size: 20px;
                  color: #2d8cf0;
                }
                span {
                  max-width: 400px;
                  font-size: 14px;
                  font-weight: 700;
                  overflow: hidden;
                  text-overflow: ellipsis;
                  white-space: nowrap;
                }
              }
              span {
                vertical-align: middle;
              }
            }
            .rightpart {
              width: 50%;
              text-align: right;
              .rightpart-text{
                font-size: 12px;
              }
              .rightpart-rating{
                font-size: 12px;
              }
              span {
                vertical-align: middle;
              }
              .ivu-rate {
                vertical-align: middle;
              }
            }
          }
        }
      }
    }
  }
  .page {
    text-align: center;
    padding-top: 40px;
  }
}
</style>